(function($){
	/*****************************************搜索框***************************************/
	$(function(){
		var 
			txt=$('.txt'),
			oUl=$('#search_message'),
			keyDown=-1;
		txt.focus(function(){
			$('label').css({color:'#ccc'});
		}).blur(function(){
			$('label').css({color:'#000'});
			oUl.css({display:'none'})
		}).keyup(function(ev){
			var oLi=$('#search_message li'),
			 ev=ev||window.event;
			if(ev.keyCode===8){
				txt.removeAttr('placeholder')
			}
			else if(ev.keyCode===38||ev.keyCode===40){
				if(ev.keyCode===38 && keyDown>0){
					keyDown--;
				}
				else if(ev.keyCode===40&& keyDown<oLi.length-1){
					keyDown++;
				}
				txt.val(oLi.css({background:'0'}).eq(keyDown).css({background:'#c40000'}).children('span').text());
				console.log(txt.val())
			}
		}).bind('input propertychange',function(){
			var val=$(this).val();
			if(val){
				$.ajax({
					type:"get",
					//url:"https://suggest.taobao.com/sug?code=utf-8&q=xiao&_ksTS=1468638023346_11087&callback=jsonp11088&area=b2c&code=utf-8&k=1&bucketid=8&src=tmall_pc&isg=ApOT1XBRwDNyS4xnsWypO6",
					url:"https://suggest.taobao.com/sug?code=utf-8&q="+val+"&_ksTS=1468638023346_11087&callback=jsonp11088&area=b2c&code=utf-8&k=1&bucketid=8&src=tmall_pc&isg=ApOT1XBRwDNyS4xnsWypO6",
					data:{val},
					dataType:'jsonp',
					success:function(data){
						var html='';
						//console.log(data)
						if(data.result.length>0){
							for(var i=0;i<data.result.length;i++){
								//console.log(data.result.length)
								html+="<li><span>"+data.result[i][0]+"</span><b>约"+data.result[i][1]+"个结果</b></li>"
							};
							if(html){
								oUl.css({display:'block'}).html(html);
							}else{
								oUl.css({display:'none'});
							}
							keyDown = -1;
						}else{
							oUl.css({display:'none'});
						}
					},
				});
			}
			else{
				oUl.html(oUl.val());
				keydown = -1;
			}
		});
	});

	/*****************************************左边的阶梯导航***********************************/
	//滚动滚动条显示导航
	$(window).scroll(function(ev){
		var 
			ev=ev||window.event,
			oDiv1=$('#nav_left #box1');
		oDiv1.each(function(i){
			if($(window).scrollTop()>=800){
				$('#nav_left').css({display:'block'});
				$('#nav_header-wrap').css({display:'block'});
				if($(window).scrollTop()>=800&&$(window).scrollTop()<1100){
					oDiv1.css({background:'#666'}).eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=1100&&$(window).scrollTop()<1400){
					oDiv1.css({background:'#666'}).eq(1).css({background:'#F7A945'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=1400&&$(window).scrollTop()<1700){
					oDiv1.css({background:'#666'}).eq(2).css({background:'#19C8A9'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=1700&&$(window).scrollTop()<2000){
					oDiv1.css({background:'#666'}).eq(3).css({background:'#F15453'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=2000&&$(window).scrollTop()<2300){
					oDiv1.css({background:'#666'}).eq(4).css({background:'#64C333'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=2300&&$(window).scrollTop()<2600){
					oDiv1.css({background:'#666'}).eq(5).css({background:'#0AA6E8'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=2600&&$(window).scrollTop()<2900){
					oDiv1.css({background:'#666'}).eq(6).css({background:'#EA5F8D'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
				else if($(window).scrollTop()>=2900&&$(window).scrollTop()<3200){
					oDiv1.css({background:'#666'}).eq(7).css({background:'#000'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}else if($(window).scrollTop()>=3200){
					oDiv1.css({background:'#666'}).eq(8).css({background:'#000'});
					oDiv1.eq(0).css({background:'#DD2727'});
				}
			}else{
				$('#nav_left').css({display:'none'});
				$('#nav_header-wrap').css({display:'none'});
			}
		})	
	});
	//点击导航滚动到所属区域
	$(function(){
		var oDiv=$('#nav_left #box1');
		oDiv.slice(0,9).each(function(i){
			oDiv.eq(i).click(function(){
				$(window).scrollTop(800+i*300);
			});
		});
		oDiv.eq(9).click(function(){
			$(window).scrollTop(0);
		})
		
	});
	/*************************************左边的阶梯导航***********************************/






})(jQuery)
	
		
		
		
	
